#ifndef PREF_COMMAND_H_
#define PREF_COMMAND_H_

#include "p_widgets.h"
#include "p_icon.h"

namespace gpyp {
namespace pref {

class PlayerList : public ListView<ConfMain::PlayerCollection> {
private:
  Application            &app_;

  CellRendererIcon        renderer_icon_;
  Gtk::CellRendererText   renderer_name_;
  Gtk::CellRendererText   renderer_command_;
  Gtk::CellRendererText   renderer_type_;
  Gtk::CellRendererToggle renderer_auto_play_;

  Gtk::TreeViewColumn     column_icon_;
  Gtk::TreeViewColumn     column_name_;
  Gtk::TreeViewColumn     column_command_;
  Gtk::TreeViewColumn     column_type_;
  Gtk::TreeViewColumn     column_auto_play_;

private:
  void icon_on_cell_data(Gtk::CellRenderer *cell, const Gtk::TreeIter &iter);
  void name_on_cell_data(Gtk::CellRenderer *cell, const Gtk::TreeIter &iter);
  void command_on_cell_data(Gtk::CellRenderer *cell, const Gtk::TreeIter &iter);
  void type_on_cell_data(Gtk::CellRenderer *cell, const Gtk::TreeIter &iter);
  void auto_play_on_cell_data(Gtk::CellRenderer *cell, const Gtk::TreeIter &iter);

  void icon_on_edited(const Glib::ustring &path, const Glib::ustring &new_icon_name);
  void name_on_edited(const Glib::ustring &path, const Glib::ustring &new_text);
  void command_on_edited(const Glib::ustring &path, const Glib::ustring &new_text);
  void type_on_edited(const Glib::ustring &path, const Glib::ustring &new_text);
  void auto_play_on_toggled(const Glib::ustring &path);

public:
  PlayerList(Application &app, Gtk::Window &parent);
};

class PlayerBox : public Gtk::VBox {
private:
  typedef ConfMain::PlayerCollection::Preset Preset;

  class PresetMenu : public Gtk::Menu {
  private:
    class Item : public Gtk::ImageMenuItem {
    private:
      Application  &app_;
      const Preset &preset_;

      Gtk::Image    image_;

    protected:
      virtual void on_activate();

    public:
      Item(Application &app, const Preset &preset);
    };

  public:
    PresetMenu(Application &app);
  };

private:
  PlayerList playerlist_;
  PresetMenu preset_menu_;

protected:
  void preset_on_clicked();

public:
  PlayerBox(Application &app, Gtk::Window &parent);
};

class Command : public Gtk::VBox {
private:
  class PresetCombo : public Gtk::ComboBoxEntryText {
  public:
    inline PresetCombo(const char **presets) {
      for(const char **p = presets; *p; ++p) {
        append_text(*p);
      }
    }
  };

private:
  PresetCombo peercast_;
  PresetCombo pcraw_proxy_;
  PresetCombo terminal_;
  PresetCombo webbrowser_;
  PresetCombo bbsbrowser_;

  PlayerBox player_;

public:
  Command(Application &app, Gtk::Window &parent);
};

}/*pref*/
}/*gpyp*/

#endif/*PREF_COMMAND_H_*/
